home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
SNDLIST-
/
UTILITIE.C
< prev
Wrap
Text File
|
1988-11-10
|
5KB
|
234 lines
/*
Sound lister
"Utilities.c"
*/
#include <DialogMgr.h>
#include <ResourceMgr.h>
#include <ToolboxUtil.h>
#include "SndList.h"
/* ----- Get resource id of sound --------------------------------------- */
short Extract(name)
register unsigned char *name;
{
register short i, j;
register unsigned char c;
unsigned char num[7];
long id;
i = j = 0;
while ((c = name[j++]) == 0xCA) /* Skip spaces */
if (j > sizeof(num)-1)
return 0x8000;
do { /* Copy id */
num[++i] = c;
if (i > sizeof(num))
return 0x8000;
} while ((c = name[j++]) != 0xCA && c);
num[0] = i;
StringToNum(num, &id);
return (short)id;
}
/* ----- Opne/close resource file --------------------------------------- */
short OpenResources(name, volume, current)
unsigned char *name; /* File name */
short volume; /* Volume reference number */
short *current; /* Old reference number */
{
register short ref;
*current = CurResFile(); /* Save current resource file reference */
if (SetVol(0L, volume))
return -1; /* Error */
SetResLoad(FALSE); /* Don't load all the resources now */
ref = OpenResFile(name);
SetResLoad(TRUE);
return ref; /* Is -1 if there was an error */
}
void CloseResources(old, ref)
short old; /* Old resource file reference */
short ref; /* The one to be closed */
{
/* Don't close appl/sys resource file */
if (ref != -1 && ref != old && ref != SysMap)
CloseResFile(ref);
UseResFile(old);
}
/* ----- Outline button in dialog --------------------------------------- */
void OutLine(dialog, item, mode)
register DialogPtr dialog;
register short item;
register short mode;
{
short kind;
Handle h;
Rect r;
PenState state;
SetPort(dialog);
GetPenState(&state);
GetDItem(dialog, item, &kind, &h, &r);
PenMode(mode);
PenPat(&black);
PenSize(3, 3);
InsetRect(&r, -4, -4);
FrameRoundRect(&r, 16, 16);
SetPenState(&state);
}
/* ----- Get edit text field in a dialog ------------------------------- */
void GetEText(dPtr, item, str)
register DialogPtr dPtr;
register short item;
register unsigned char *str;
{
short theType;
Handle theItem;
Rect theBox;
GetDItem(dPtr, item, &theType, &theItem, &theBox);
GetIText(theItem, str);
}
/* ----- Set edit text field in a dialog ------------------------------- */
void SetEText(dPtr, item, str)
register DialogPtr dPtr;
register short item;
register unsigned char *str;
{
short theType;
Handle theItem;
Rect theBox;
GetDItem(dPtr, item, &theType, &theItem, &theBox);
SetIText(theItem, str);
}
/* ----- Get the value of a control ------------------------------------ */
short GetCheck(dPtr, ChkItem)
register DialogPtr dPtr;
register short ChkItem;
{
short theType;
Handle theItem;
Rect theBox;
GetDItem(dPtr, ChkItem, &theType, &theItem, &theBox);
return GetCtlValue(theItem);
}
/* ----- Set the value of a control ------------------------------------ */
void SetCheck(dPtr, ChkItem, value)
register DialogPtr dPtr;
short ChkItem;
short value;
{
short theType;
Handle theItem;
Rect theBox;
GetDItem(dPtr, ChkItem, &theType, &theItem, &theBox);
SetCtlValue(theItem, value);
}
/* ----- Center dialog or alert template ------------------------------- */
void CenterDialog(templateType, templateID, bounds)
register long templateType; /* 'ALRT' or 'DLOG' */
register short templateID;
register Rect *bounds;
{
register Rect *p;
register Rect **h; /* Templates start with boundsRect */
register short width, height;
if (!(h = (Rect **)GetResource(templateType, templateID)))
return;
p = *h;
width = p->right - p->left;
height = p->bottom - p->top;
p->bottom = bounds->bottom -
((bounds->bottom - bounds->top - height) >> 1);
p->top = p->bottom - height;
p->left = bounds->left +
((bounds->right - bounds->left - width) >> 1);
p->right = p->left + width;
}
/* ----- Calculate where to put a centered dialog box ------------------ */
void GetDlogOrigin(dlogID, where, bounds)
register short dlogID;
register Point *where;
register Rect *bounds;
{
register Rect *p;
register Rect **h; /* Templates start with boundsRect */
if (!(h = (Rect **)GetResource('DLOG', dlogID))) {
where->v = where->h = 80;
return;
}
p = *h;
where->h = bounds->left +
((bounds->right - bounds->left - (p->right - p->left)) >> 1);
where->v = bounds->top +
((bounds->bottom - bounds->top - (p->bottom - p->top)) >> 1);
}
/* ----- Hilite control ----------------------------------------------- */
SetHilite(dPtr, ChkItem, Value)
DialogPtr dPtr;
short ChkItem;
short Value;
{
short theType;
Handle theItem;
Rect theBox;
GetDItem(dPtr, ChkItem, &theType, &theItem, &theBox);
HiliteControl(theItem, Value);
}
/* ----- Error message ------------------------------------------------- */
void Message(n, code)
register short n;
register short code;
{
register StringHandle h;
register DialogPtr dialogP;
short item;
unsigned char number[10];
InitCursor();
SysBeep(1);
if (h = GetString(n)) {
HLock(h);
if (code)
NumToString((long)code, number);
else
number[0] = 0;
ParamText(*h, number, EmptyStr, EmptyStr);
CenterDialog('DLOG', rMessage, &Bounds);
if (dialogP = GetNewDialog(rMessage, 0L, -1L)) {
OutLine(dialogP, 1, patCopy);
ModalDialog(0L, &item);
DisposDialog(dialogP);
}
HUnlock(h);
}
}